Page({


    data:{
        userInfo:{},
        hasUserInfo: false,
        canIUseGetUserProfile: false,
        userID:'',
        xueli:'',
        nianji:'',
        xuexiao:'',
        sex:'',
        phone:'',
        teacher:''
    },

    onLoad() {
      
        if (wx.getUserProfile) {
            this.setData({
                canIUseGetUserProfile: true
            })
        }
        this.login();
    },

    // 登录
    login() {
        let user = wx.getStorageSync('user');
        // console.log(user);
        if (user) {
            this.setData({
                userInfo: user.userInfo,
                hasUserInfo: true,
                userID: user.cloudID
            })
        }

    },
    
    // 退出登录
    layout(){
        wx.showModal({
          title: '提示',
          content:'确定退出登录吗',
          success:(res)=>{
            //   console.log(res);
            if(res.confirm){
                wx.clearStorage()
                wx.reLaunch({
                  url: '/pages/home/home',
                })
            }
          }
        })
    },

    change(e){
        console.log(e.detail.value);
    },

    // 用户信息
    getUserProfile(e) {
        let that = this
        // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认
        // 开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
        wx.getUserProfile({
            desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
            success: (res) => {
                wx.showLoading({
                    title: '正在登录.....',
                })

                let that = this;
                setTimeout(function () {
                    wx.hideLoading()
                    // 记录时长
                    // that.recordduration();
                    that.setData({
                        userInfo: res.userInfo,
                        hasUserInfo: true,
                        userID: res.cloudID
                    })
                    wx.setStorageSync('userID', res.cloudID)
                    wx.setStorageSync('user', res)
                }, 2000)

            }
        })
    },
 
    // 
    onUnload:function(){
    
    },

   
})